package com.dhsc.util;

import java.util.Locale;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @ClassName:  SpringContextUtil
 * @Description: 系统bean帮助类 
 * @date:   2020年12月24日 下午5:13:00       
 * @author: chenlong
 * @Copyright:  迅优智超
 */
@Component
public class SpringContextUtil implements ApplicationContextAware
{

	private static ApplicationContext context;

	@Override
	@SuppressWarnings("static-access")
	public void setApplicationContext(ApplicationContext contex) throws BeansException
	{
		this.context = contex;
	}

	@SuppressWarnings("unchecked")
	public static <T> T getBean(String beanName)
	{
		return (T) context.getBean(beanName);
	}

	public static <T> T getBean(Class<T> clazz)
	{
		return context.getBean(clazz);
	}

	public static String getMessage(String key)
	{
		return context.getMessage(key, null, Locale.getDefault());
	}

}
